<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="框架承揽合同" prop="contractFramework.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择框架承揽合同"
            labelName = 'contractNumber'
            labelValue = 'id'
            :value = "inputForm.contractFramework.id"
            :limit="1"
            @getValue='(value) => {inputForm.contractFramework.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'contractNumber',
              label: '合同编号'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'contractNumber',
              label: '合同编号'
            }
            ]"
            dataListUrl="/epc/contractframework/contractFramework/list"
            entityBeanName="contractFramework"
            queryEntityUrl="/epc/contractframework/contractFramework/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="申请部门" prop="applyDepartment"
                :rules="[
                 ]">
              <el-input v-model="inputForm.applyDepartment" placeholder="请填写申请部门"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="申请人" prop="proposer"
                :rules="[
                 ]">
              <el-input v-model="inputForm.proposer" placeholder="请填写申请人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="申请日期" prop="applicationDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.applicationDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设计分类" prop="designClassification"
                :rules="[
                 ]">
                <el-select v-model="inputForm.designClassification" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('design_classification')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="甲方" prop="firstParty.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择甲方"
            labelName = 'name'
            labelValue = 'id'
            :value = "inputForm.firstParty.id"
            :limit="1"
            @getValue='(value) => {inputForm.firstParty.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '姓名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '姓名'
            }
            ]"
            dataListUrl="/epc/pmfirstparty/firstParty/list"
            entityBeanName="firstParty"
            queryEntityUrl="/epc/pmfirstparty/firstParty/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程来源" prop="engineeringSource"
                :rules="[
                 ]">
              <el-input v-model="inputForm.engineeringSource" placeholder="请填写工程来源"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程大项" prop="singleProject"
                :rules="[
                 ]">
              <el-input v-model="inputForm.singleProject" placeholder="请填写工程大项"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程属性" prop="engineeringProperties"
                :rules="[
                 ]">
                <el-select v-model="inputForm.engineeringProperties" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('engineering_properties')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单位名称" prop="officeName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.officeName" placeholder="请填写单位名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="归属分公司" prop="filiale.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="filiale"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.filiale.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.filiale.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="归属项目部" prop="projectDepartment.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="projectDepartment"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.projectDepartment.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.projectDepartment.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="委托日期" prop="entrustmentDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.entrustmentDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程施工性质" prop="natureEngineeringConstruction"
                :rules="[
                 ]">
                <el-select v-model="inputForm.natureEngineeringConstruction" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('nature_engineering_construction')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="结算性质" prop="settlementProperties"
                :rules="[
                 ]">
                <el-select v-model="inputForm.settlementProperties" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('settlement_properties')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="建设性质" prop="constructionNature"
                :rules="[
                 ]">
                <el-select v-model="inputForm.constructionNature" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('construction_nature')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="专业id" prop="major.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择专业id"
            labelName = 'majorName'
            labelValue = 'id'
            :value = "inputForm.major.id"
            :limit="1"
            @getValue='(value) => {inputForm.major.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'majorName',
              label: '专业名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'majorName',
              label: '专业名称'
            }
            ]"
            dataListUrl="/epc/contractmajor/contractMajor/list"
            entityBeanName="contractMajor"
            queryEntityUrl="/epc/contractmajor/contractMajor/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工区域" prop="constructionRegion"
                :rules="[
                 ]">
              <el-input v-model="inputForm.constructionRegion" placeholder="请填写施工区域"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="合作方性质" prop="naturePartner"
                :rules="[
                 ]">
                <el-select v-model="inputForm.naturePartner" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('nature_partner')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="合作方" prop="partner"
                :rules="[
                 ]">
              <el-input v-model="inputForm.partner" placeholder="请填写合作方"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程编号" prop="jobNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.jobNumber" placeholder="请填写工程编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程状态" prop="projectStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.projectStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('project_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="建设单位" prop="constructionUnit.id"
                :rules="[
                  {required: true, message:'建设单位不能为空', trigger:'blur'}
                 ]">
          <SelectTree
                      ref="constructionUnit"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.constructionUnit.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.constructionUnit.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="部门经理" prop="departmentManager"
                :rules="[
                 ]">
              <el-input v-model="inputForm.departmentManager" placeholder="请填写部门经理"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="部门经理联系电话" prop="departmentManagerPhone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.departmentManagerPhone" placeholder="请填写部门经理联系电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目经理" prop="projectManager.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.projectManager.id" @getValue='(value) => {inputForm.projectManager.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目经理联系电话" prop="projectManagerPhone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.projectManagerPhone" placeholder="请填写项目经理联系电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工单位" prop="constructionOrganization.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="constructionOrganization"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.constructionOrganization.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.constructionOrganization.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工负责人" prop="constructionPrincipal"
                :rules="[
                 ]">
              <el-input v-model="inputForm.constructionPrincipal" placeholder="请填写施工负责人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工负责人联系电话" prop="constructionPrincipalPhone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.constructionPrincipalPhone" placeholder="请填写施工负责人联系电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设计人" prop="designerPeople"
                :rules="[
                 ]">
              <el-input v-model="inputForm.designerPeople" placeholder="请填写设计人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设计人联系电话" prop="designerPhone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.designerPhone" placeholder="请填写设计人联系电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="监理单位" prop="supervisingUnit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.supervisingUnit" placeholder="请填写监理单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="监理负责人" prop="supervisingPrincipal"
                :rules="[
                 ]">
              <el-input v-model="inputForm.supervisingPrincipal" placeholder="请填写监理负责人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="现场监理" prop="siteSupervision"
                :rules="[
                 ]">
              <el-input v-model="inputForm.siteSupervision" placeholder="请填写现场监理"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="现场监理联系电话" prop="siteSupervisionPhone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.siteSupervisionPhone" placeholder="请填写现场监理联系电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工作量" prop="workload"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workload" placeholder="请填写工作量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="除税文本设计费" prop="additionTaxDesignFee"
                :rules="[
                 ]">
              <el-input v-model="inputForm.additionTaxDesignFee" placeholder="请填写除税文本设计费"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="增值税" prop="addedValueTax"
                :rules="[
                 ]">
                <el-select v-model="inputForm.addedValueTax" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('added_value_tax')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="合作比例" prop="proportionCooperation"
                :rules="[
                 ]">
              <el-input v-model="inputForm.proportionCooperation" placeholder="请填写合作比例"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="勘探人员" prop="scout.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.scout.id" @getValue='(value) => {inputForm.scout.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设计人员" prop="designer.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.designer.id" @getValue='(value) => {inputForm.designer.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="二设人员" prop="secondSetPersonnel.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.secondSetPersonnel.id" @getValue='(value) => {inputForm.secondSetPersonnel.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预算人员" prop="budgeter.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.budgeter.id" @getValue='(value) => {inputForm.budgeter.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="文本人员" prop="textPart.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.textPart.id" @getValue='(value) => {inputForm.textPart.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="归档状态" prop="archiveStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.archiveStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('archive_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import UserSelect from '@/components/userSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          contractFramework: {
            id: ''
          },
          applyDepartment: '',
          proposer: '',
          applicationDate: '',
          designClassification: '',
          firstParty: {
            id: ''
          },
          engineeringSource: '',
          singleProject: '',
          engineeringProperties: '',
          officeName: '',
          filiale: {
            id: ''
          },
          projectDepartment: {
            id: ''
          },
          entrustmentDate: '',
          natureEngineeringConstruction: '',
          settlementProperties: '',
          constructionNature: '',
          major: {
            id: ''
          },
          constructionRegion: '',
          naturePartner: '',
          partner: '',
          jobNumber: '',
          projectStatus: '',
          constructionUnit: {
            id: ''
          },
          departmentManager: '',
          departmentManagerPhone: '',
          projectManager: {
            id: ''
          },
          projectManagerPhone: '',
          constructionOrganization: {
            id: ''
          },
          constructionPrincipal: '',
          constructionPrincipalPhone: '',
          designerPeople: '',
          designerPhone: '',
          supervisingUnit: '',
          supervisingPrincipal: '',
          siteSupervision: '',
          siteSupervisionPhone: '',
          workload: '',
          additionTaxDesignFee: '',
          addedValueTax: '',
          proportionCooperation: '',
          scout: {
            id: ''
          },
          designer: {
            id: ''
          },
          secondSetPersonnel: {
            id: ''
          },
          budgeter: {
            id: ''
          },
          textPart: {
            id: ''
          },
          archiveStatus: '',
          remarks: ''
        }
      }
    },
    components: {
      GridSelect,
      SelectTree,
      UserSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建设计归档`
        } else if (method === 'edit') {
          this.title = '修改设计归档'
        } else if (method === 'view') {
          this.title = '查看设计归档'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/epc/pmdesignachive/designArchive/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.designArchive)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/pmdesignachive/designArchive/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>